package com.wpx.log.core.handler.param;

import java.lang.reflect.Field;
import java.util.Enumeration;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Component;

import com.wpx.log.core.LogContext;
import com.wpx.log.core.LogRequestContext;
import com.wpx.log.core.module.LogParam;

@Component
public class ILogFormParamTypePolicy implements ILogParamTypePolicy {

	@Override
	public String type() {
		return "application/x-www-form-urlencoded";
	}

	@Override
	public void parseParam(LogContext logContext, LogRequestContext logRequestContext, Field logField, final List<LogParam> params) {
		
			HttpServletRequest request = logRequestContext.getHttpServletRequest();
			Enumeration<String> names = request.getParameterNames();	
			while(names.hasMoreElements()) {
				String name = names.nextElement();
				LogParam param = new LogParam(name, request.getParameter(name), LogParam.TYPE_BASE);
				params.add(param);
			}
			
	}

}
